
package customers;

import avenue.MyWindowEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import javax.persistence.EntityManager;
import javax.swing.JFrame;
import model.Customer;
import model.DBManager;
import model.Vehicle;


 // JPanel που περιέχει τη φόρμα με τα στοιχεία ένος πελάτη
 /**
 * @author Nikos
 */

public class EditClientForm extends javax.swing.JFrame {
   // Αναφορά στο frame πατέρα, δηλαδή στο frame που είναι υπεύθυνο για την προβολή
    // του JPanel
     // Δημιουργούμε την επικοινωνία της EditClientForm με την βάση μας
    public EditClientForm() {
        em = DBManager.em;
        if ( !(em.getTransaction().isActive()) ){
            em.getTransaction().begin();
        }
        initComponents();
    }
      
     public EditClientForm(Customer c, boolean readOnly) {
        em = DBManager.em;
        customer1=c;
        this.readOnly = readOnly;
        if ( !(em.getTransaction().isActive()) ){
            em.getTransaction().begin();
        }
        initComponents();
    }
    /**
     * Creates new form EditClientForm
     */
   
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        customer2 = customer1;
        vehicleQuery = em.createQuery("select v from Vehicle v where v.custId=:customer").setParameter("customer",customer2);
        vehicleList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(vehicleQuery.getResultList());
        categoryCellRenderer1 = new avenue.CategoryCellRenderer();
        idLabel = new javax.swing.JLabel();
        lnameLabel = new javax.swing.JLabel();
        TextFieldFName = new javax.swing.JTextField();
        TextFieldLName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        newButton = new javax.swing.JButton();
        delButton = new javax.swing.JButton();
        processButton = new javax.swing.JButton();
        fnameLabel = new javax.swing.JLabel();
        TextFieldId = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        adtLabel = new javax.swing.JLabel();
        TextFieldAFM = new javax.swing.JTextField();
        afmLabel = new javax.swing.JLabel();
        TextFieldADT = new javax.swing.JTextField();
        invalidButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        cityLabel = new javax.swing.JLabel();
        TextFieldCity = new javax.swing.JTextField();
        addrLabel = new javax.swing.JLabel();
        TextFieldAddress = new javax.swing.JTextField();
        zipLabel = new javax.swing.JLabel();
        TextFieldZipcode = new javax.swing.JTextField();
        phoneLabel = new javax.swing.JLabel();
        TextFieldPhone = new javax.swing.JTextField();
        emailLabel = new javax.swing.JLabel();
        TextFieldEmail = new javax.swing.JTextField();

        categoryCellRenderer1.setText("categoryCellRenderer1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Διαχείριση Πελάτη");

        idLabel.setText("Κωδ.Πελάτη: ");
        idLabel.setToolTipText("");

        lnameLabel.setText("Επώνυμο: ");

        TextFieldFName.setEditable(!readOnly);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${FName}"), TextFieldFName, org.jdesktop.beansbinding.BeanProperty.create("text"), "FName");
        bindingGroup.addBinding(binding);

        TextFieldFName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextFieldFNameActionPerformed(evt);
            }
        });

        TextFieldLName.setEditable(!readOnly);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${LName}"), TextFieldLName, org.jdesktop.beansbinding.BeanProperty.create("text"), "LName");
        bindingGroup.addBinding(binding);

        jLabel3.setText("Οχήματα : ");
        jLabel3.setToolTipText("");

        newButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add.gif"))); // NOI18N
        newButton.setText("Νέο");
        newButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newButtonActionPerformed(evt);
            }
        });

        delButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/remove.gif"))); // NOI18N
        delButton.setText("Διαγραφή");
        delButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delButtonActionPerformed(evt);
            }
        });

        processButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/edit1.png"))); // NOI18N
        processButton.setText("Επεξεργασία");
        processButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                processButtonActionPerformed(evt);
            }
        });

        fnameLabel.setText("Όνομα: ");
        fnameLabel.setToolTipText("");

        TextFieldId.setEditable(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${id}"), TextFieldId, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        adtLabel.setText("ΑΔΤ: ");
        adtLabel.setToolTipText("");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${afm}"), TextFieldAFM, org.jdesktop.beansbinding.BeanProperty.create("text"), "afm");
        bindingGroup.addBinding(binding);

        afmLabel.setText("ΑΦΜ: ");
        afmLabel.setToolTipText("");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${adt}"), TextFieldADT, org.jdesktop.beansbinding.BeanProperty.create("text"), "adt");
        bindingGroup.addBinding(binding);

        invalidButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cancel.gif"))); // NOI18N
        invalidButton.setText("Ακυρο");
        invalidButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                invalidButtonActionPerformed(evt);
            }
        });

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.gif"))); // NOI18N
        saveButton.setText("Αποθήκευση");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicleList, jTable2, "");
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${regNumber}"));
        columnBinding.setColumnName("Αρ.κυκλοφορίας");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${modelType}"));
        columnBinding.setColumnName("Τύπος");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${factoryName}"));
        columnBinding.setColumnName("Κατασκευαστής");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${colour}"));
        columnBinding.setColumnName("Χρώμα");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane2.setViewportView(jTable2);

        cityLabel.setText("Πόλη:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${city}"), TextFieldCity, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        addrLabel.setText("Διεύθυνση:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${address}"), TextFieldAddress, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        zipLabel.setText("Ταχ.κώδικας:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${zipCode}"), TextFieldZipcode, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        phoneLabel.setText("Τηλέφωνο:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${phone}"), TextFieldPhone, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        emailLabel.setText("Διεύθ.Ηλεκτρ.Ταχυδρομίου:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customer2, org.jdesktop.beansbinding.ELProperty.create("${email}"), TextFieldEmail, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(idLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(TextFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(fnameLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(TextFieldFName, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lnameLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(TextFieldLName, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(adtLabel)
                                    .addComponent(afmLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(TextFieldAFM)
                                    .addComponent(TextFieldADT, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(addrLabel)
                                    .addComponent(cityLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(TextFieldCity, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(zipLabel))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(TextFieldAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(phoneLabel)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(TextFieldZipcode)
                                    .addComponent(TextFieldPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addComponent(emailLabel)
                                .addGap(18, 18, 18)
                                .addComponent(TextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(34, 34, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2)
                            .addComponent(jSeparator1)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(invalidButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(saveButton)))
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(newButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(delButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(processButton))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jSeparator2)
                                .addGap(71, 71, 71)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(idLabel)
                    .addComponent(TextFieldFName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lnameLabel)
                    .addComponent(TextFieldLName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TextFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fnameLabel))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(adtLabel)
                    .addComponent(TextFieldADT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cityLabel)
                    .addComponent(TextFieldCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(zipLabel)
                    .addComponent(TextFieldZipcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(emailLabel)
                    .addComponent(TextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(afmLabel)
                            .addComponent(TextFieldAFM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(addrLabel)
                            .addComponent(TextFieldAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(phoneLabel)))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TextFieldPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newButton)
                    .addComponent(delButton)
                    .addComponent(processButton))
                .addGap(2, 2, 2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveButton)
                    .addComponent(invalidButton)))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Εάν πατηθεί το κουμπί "Νέο" δημιουργούμε ένα νέο όχημα
    // το οποίο κάνουμε persist στην βάση μας
    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
      
       v = new Vehicle();
       em.persist(v);
       VehicleDialog vf = new VehicleDialog(v);
       
       vf.setVisible(true);
       thisFrame=this;
       thisFrame.setEnabled(false);
        vf.addWindowListener(new WindowListener() {
            public void windowClosed(WindowEvent arg0) {
                System.out.println("Window close event occur");
                if (v != null){
                    v.setCustId(customer1);
                    // Εάν η λίστα με τα οχήματα είναι κενή δημιουργούμαι νέα λίστα
                    if (vehicleList==null){
                        vehicleList = new ArrayList<Vehicle>();
                    }
                    // προσθέτουμε στην λίστα το νέο όχημα
                    vehicleList.add(v);
                    int row = vehicleList.size() - 1;
                    jTable2.setRowSelectionInterval(row, row);
                    jTable2.scrollRectToVisible(jTable2.getCellRect(row, 0, true));
                    thisFrame.setEnabled(true);
                }
                else{
                    em.getTransaction().rollback();
                    em.getTransaction().begin();
                }
            }
            public void windowActivated(WindowEvent arg0) {
                System.out.println("Window Activated");
            }
            public void windowClosing(WindowEvent arg0) {
                System.out.println("Window Closing");
            }
            public void windowDeactivated(WindowEvent arg0) {
                System.out.println("Window Deactivated");
            }
            public void windowDeiconified(WindowEvent arg0) {
                System.out.println("Window Deiconified");
            }
            public void windowIconified(WindowEvent arg0) {
                System.out.println("Window Iconified");
            }
            public void windowOpened(WindowEvent arg0) {
                System.out.println("Window Opened");
            }
        });
       
    }//GEN-LAST:event_newButtonActionPerformed
    // Όταν θα πατηθεί το πλήκτρο "Επεξεργασία" για τα στοιχεία ενός πελάτη θα κληθεί
    // η φόρμα  VehicleDialog για να επεξεργαστούμε τα στοιχεία του οχήματος του πελάτη.
    private void processButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processButtonActionPerformed
        
        int s = this.jTable2.getSelectedRow();
        Vehicle v = this.customer1.getVehicleList().get(s);
        
        VehicleDialog vf = new VehicleDialog(v);
        vf.setVisible(true);
        if (v != null){
           
            em.persist(v);
            jTable2.setRowSelectionInterval(s, s);
            jTable2.scrollRectToVisible(jTable2.getCellRect(s, 0, true));
       }
        
    }//GEN-LAST:event_processButtonActionPerformed
// Εφόσον πατηθεί το πλήκτρο "Αποθήκευση" αποθηκεύει την εγγραφή και κλείνει η φόρμα 
// MyWindowEvent γίνεται true 
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
       
        MyWindowEvent we = new MyWindowEvent(this, WindowEvent.WINDOW_CLOSED,true);
        for (WindowListener l : this.getWindowListeners()) {
            l.windowClosed(we);
       }
       this.setVisible(false); 
    }//GEN-LAST:event_saveButtonActionPerformed
    // Εφόσον πατηθεί το πλήκτρο "Άκυρο" κλείνει η φόρμα χωρίς να αποθηκευτή η εγγραφή αφού το
    // MyWindowEvent γίνεται false 
    private void invalidButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_invalidButtonActionPerformed
 
        MyWindowEvent we = new MyWindowEvent(this, WindowEvent.WINDOW_CLOSED,false);
        for (WindowListener l : this.getWindowListeners()) {
            l.windowClosed(we);
       }
       this.setVisible(false); 
         
    }//GEN-LAST:event_invalidButtonActionPerformed

    private void TextFieldFNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextFieldFNameActionPerformed
     
    }//GEN-LAST:event_TextFieldFNameActionPerformed
    // Εφόσον πατηθεί το πλήκτρο "Διαγραφή" και εφόσον υπάρχουν εγγραφές, να πάρει την πρώτη 
    // εγγραφή του πίνακα και να την διαγράψει
    private void delButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delButtonActionPerformed
        
        int s=jTable2.getSelectedRow();
        if (s>=0) {
            v = vehicleList.get(jTable2.convertRowIndexToModel(s));
            vehicleList.remove(v);
            em.remove(v);
        }
    }//GEN-LAST:event_delButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EditClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EditClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EditClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EditClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                
              new EditClientForm().setVisible(true);
             
            }
        });
    }

    public boolean isReadOnly() {
        return readOnly;
    }

    public void setReadOnly(boolean readOnly) {
        this.readOnly = readOnly;
    }
   
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField TextFieldADT;
    private javax.swing.JTextField TextFieldAFM;
    private javax.swing.JTextField TextFieldAddress;
    private javax.swing.JTextField TextFieldCity;
    private javax.swing.JTextField TextFieldEmail;
    private javax.swing.JTextField TextFieldFName;
    private javax.swing.JTextField TextFieldId;
    private javax.swing.JTextField TextFieldLName;
    private javax.swing.JTextField TextFieldPhone;
    private javax.swing.JTextField TextFieldZipcode;
    private javax.swing.JLabel addrLabel;
    private javax.swing.JLabel adtLabel;
    private javax.swing.JLabel afmLabel;
    private avenue.CategoryCellRenderer categoryCellRenderer1;
    private javax.swing.JLabel cityLabel;
    private model.Customer customer2;
    private javax.swing.JButton delButton;
    private javax.swing.JLabel emailLabel;
    private javax.swing.JLabel fnameLabel;
    private javax.swing.JLabel idLabel;
    private javax.swing.JButton invalidButton;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTable jTable2;
    private javax.swing.JLabel lnameLabel;
    private javax.swing.JButton newButton;
    private javax.swing.JLabel phoneLabel;
    private javax.swing.JButton processButton;
    private javax.swing.JButton saveButton;
    private java.util.List<model.Vehicle> vehicleList;
    private javax.persistence.Query vehicleQuery;
    private javax.swing.JLabel zipLabel;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    private EntityManager em;
    Vehicle v;
    Customer customer1;
    JFrame thisFrame;
    boolean readOnly;
}
